﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwBlagajnaStavkaProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwBlagajnaStavkaProviderBaseCore : EntityViewProviderBase<VwBlagajnaStavka>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwBlagajnaStavka&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwBlagajnaStavka&gt;"/></returns>
		protected static VList&lt;VwBlagajnaStavka&gt; Fill(DataSet dataSet, VList<VwBlagajnaStavka> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwBlagajnaStavka>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwBlagajnaStavka&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwBlagajnaStavka>"/></returns>
		protected static VList&lt;VwBlagajnaStavka&gt; Fill(DataTable dataTable, VList<VwBlagajnaStavka> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwBlagajnaStavka c = new VwBlagajnaStavka();
					c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
					c.IDBlagajnaIzvjestaj = (Convert.IsDBNull(row["IDBlagajnaIzvjestaj"]))?(int)0:(System.Int32)row["IDBlagajnaIzvjestaj"];
					c.DatumDokumenta = (Convert.IsDBNull(row["DatumDokumenta"]))?DateTime.MinValue:(System.DateTime)row["DatumDokumenta"];
					c.Ulaz = (Convert.IsDBNull(row["Ulaz"]))?0:(System.Decimal)row["Ulaz"];
					c.Izlaz = (Convert.IsDBNull(row["Izlaz"]))?0:(System.Decimal)row["Izlaz"];
					c.DateUICreated = (Convert.IsDBNull(row["DateUICreated"]))?DateTime.MinValue:(System.DateTime)row["DateUICreated"];
					c.Opis = (Convert.IsDBNull(row["Opis"]))?string.Empty:(System.String)row["Opis"];
					c.IDKonto = (Convert.IsDBNull(row["IDKonto"]))?(int)0:(System.Int32)row["IDKonto"];
					c.KontoSifra = (Convert.IsDBNull(row["KontoSifra"]))?string.Empty:(System.String)row["KontoSifra"];
					c.Primatelj = (Convert.IsDBNull(row["Primatelj"]))?string.Empty:(System.String)row["Primatelj"];
					c.IDKlijent = (Convert.IsDBNull(row["IDKlijent"]))?(int)0:(System.Int32?)row["IDKlijent"];
					c.IDOrganizacija = (Convert.IsDBNull(row["IDOrganizacija"]))?(int)0:(System.Int32)row["IDOrganizacija"];
					c.Mjesto = (Convert.IsDBNull(row["Mjesto"]))?string.Empty:(System.String)row["Mjesto"];
					c.OrgSifra = (Convert.IsDBNull(row["OrgSifra"]))?string.Empty:(System.String)row["OrgSifra"];
					c.OrgNaziv = (Convert.IsDBNull(row["OrgNaziv"]))?string.Empty:(System.String)row["OrgNaziv"];
					c.RedniBrojStavke = (Convert.IsDBNull(row["RedniBrojStavke"]))?(long)0:(System.Int64?)row["RedniBrojStavke"];
					c.TipStavke = (Convert.IsDBNull(row["TipStavke"]))?(int)0:(System.Int32)row["TipStavke"];
					c.NazivTipStavke = (Convert.IsDBNull(row["NazivTipStavke"]))?string.Empty:(System.String)row["NazivTipStavke"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwBlagajnaStavka&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwBlagajnaStavka&gt;"/></returns>
		protected VList<VwBlagajnaStavka> Fill(IDataReader reader, VList<VwBlagajnaStavka> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwBlagajnaStavka entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwBlagajnaStavka>("VwBlagajnaStavka",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwBlagajnaStavka();
					}
					entity.ID = (System.Int32)reader["ID"];
					//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
					entity.IDBlagajnaIzvjestaj = (System.Int32)reader["IDBlagajnaIzvjestaj"];
					//entity.IDBlagajnaIzvjestaj = (Convert.IsDBNull(reader["IDBlagajnaIzvjestaj"]))?(int)0:(System.Int32)reader["IDBlagajnaIzvjestaj"];
					entity.DatumDokumenta = (System.DateTime)reader["DatumDokumenta"];
					//entity.DatumDokumenta = (Convert.IsDBNull(reader["DatumDokumenta"]))?DateTime.MinValue:(System.DateTime)reader["DatumDokumenta"];
					entity.Ulaz = (System.Decimal)reader["Ulaz"];
					//entity.Ulaz = (Convert.IsDBNull(reader["Ulaz"]))?0:(System.Decimal)reader["Ulaz"];
					entity.Izlaz = (System.Decimal)reader["Izlaz"];
					//entity.Izlaz = (Convert.IsDBNull(reader["Izlaz"]))?0:(System.Decimal)reader["Izlaz"];
					entity.DateUICreated = (System.DateTime)reader["DateUICreated"];
					//entity.DateUICreated = (Convert.IsDBNull(reader["DateUICreated"]))?DateTime.MinValue:(System.DateTime)reader["DateUICreated"];
					entity.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (System.String)reader["Opis"];
					//entity.Opis = (Convert.IsDBNull(reader["Opis"]))?string.Empty:(System.String)reader["Opis"];
					entity.IDKonto = (System.Int32)reader["IDKonto"];
					//entity.IDKonto = (Convert.IsDBNull(reader["IDKonto"]))?(int)0:(System.Int32)reader["IDKonto"];
					entity.KontoSifra = (System.String)reader["KontoSifra"];
					//entity.KontoSifra = (Convert.IsDBNull(reader["KontoSifra"]))?string.Empty:(System.String)reader["KontoSifra"];
					entity.Primatelj = reader.IsDBNull(reader.GetOrdinal("Primatelj")) ? null : (System.String)reader["Primatelj"];
					//entity.Primatelj = (Convert.IsDBNull(reader["Primatelj"]))?string.Empty:(System.String)reader["Primatelj"];
					entity.IDKlijent = reader.IsDBNull(reader.GetOrdinal("IDKlijent")) ? null : (System.Int32?)reader["IDKlijent"];
					//entity.IDKlijent = (Convert.IsDBNull(reader["IDKlijent"]))?(int)0:(System.Int32?)reader["IDKlijent"];
					entity.IDOrganizacija = (System.Int32)reader["IDOrganizacija"];
					//entity.IDOrganizacija = (Convert.IsDBNull(reader["IDOrganizacija"]))?(int)0:(System.Int32)reader["IDOrganizacija"];
					entity.Mjesto = reader.IsDBNull(reader.GetOrdinal("Mjesto")) ? null : (System.String)reader["Mjesto"];
					//entity.Mjesto = (Convert.IsDBNull(reader["Mjesto"]))?string.Empty:(System.String)reader["Mjesto"];
					entity.OrgSifra = (System.String)reader["OrgSifra"];
					//entity.OrgSifra = (Convert.IsDBNull(reader["OrgSifra"]))?string.Empty:(System.String)reader["OrgSifra"];
					entity.OrgNaziv = (System.String)reader["OrgNaziv"];
					//entity.OrgNaziv = (Convert.IsDBNull(reader["OrgNaziv"]))?string.Empty:(System.String)reader["OrgNaziv"];
					entity.RedniBrojStavke = reader.IsDBNull(reader.GetOrdinal("RedniBrojStavke")) ? null : (System.Int64?)reader["RedniBrojStavke"];
					//entity.RedniBrojStavke = (Convert.IsDBNull(reader["RedniBrojStavke"]))?(long)0:(System.Int64?)reader["RedniBrojStavke"];
					entity.TipStavke = (System.Int32)reader["TipStavke"];
					//entity.TipStavke = (Convert.IsDBNull(reader["TipStavke"]))?(int)0:(System.Int32)reader["TipStavke"];
					entity.NazivTipStavke = (System.String)reader["NazivTipStavke"];
					//entity.NazivTipStavke = (Convert.IsDBNull(reader["NazivTipStavke"]))?string.Empty:(System.String)reader["NazivTipStavke"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwBlagajnaStavka"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwBlagajnaStavka"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwBlagajnaStavka entity)
		{
			reader.Read();
			entity.ID = (System.Int32)reader["ID"];
			//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
			entity.IDBlagajnaIzvjestaj = (System.Int32)reader["IDBlagajnaIzvjestaj"];
			//entity.IDBlagajnaIzvjestaj = (Convert.IsDBNull(reader["IDBlagajnaIzvjestaj"]))?(int)0:(System.Int32)reader["IDBlagajnaIzvjestaj"];
			entity.DatumDokumenta = (System.DateTime)reader["DatumDokumenta"];
			//entity.DatumDokumenta = (Convert.IsDBNull(reader["DatumDokumenta"]))?DateTime.MinValue:(System.DateTime)reader["DatumDokumenta"];
			entity.Ulaz = (System.Decimal)reader["Ulaz"];
			//entity.Ulaz = (Convert.IsDBNull(reader["Ulaz"]))?0:(System.Decimal)reader["Ulaz"];
			entity.Izlaz = (System.Decimal)reader["Izlaz"];
			//entity.Izlaz = (Convert.IsDBNull(reader["Izlaz"]))?0:(System.Decimal)reader["Izlaz"];
			entity.DateUICreated = (System.DateTime)reader["DateUICreated"];
			//entity.DateUICreated = (Convert.IsDBNull(reader["DateUICreated"]))?DateTime.MinValue:(System.DateTime)reader["DateUICreated"];
			entity.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (System.String)reader["Opis"];
			//entity.Opis = (Convert.IsDBNull(reader["Opis"]))?string.Empty:(System.String)reader["Opis"];
			entity.IDKonto = (System.Int32)reader["IDKonto"];
			//entity.IDKonto = (Convert.IsDBNull(reader["IDKonto"]))?(int)0:(System.Int32)reader["IDKonto"];
			entity.KontoSifra = (System.String)reader["KontoSifra"];
			//entity.KontoSifra = (Convert.IsDBNull(reader["KontoSifra"]))?string.Empty:(System.String)reader["KontoSifra"];
			entity.Primatelj = reader.IsDBNull(reader.GetOrdinal("Primatelj")) ? null : (System.String)reader["Primatelj"];
			//entity.Primatelj = (Convert.IsDBNull(reader["Primatelj"]))?string.Empty:(System.String)reader["Primatelj"];
			entity.IDKlijent = reader.IsDBNull(reader.GetOrdinal("IDKlijent")) ? null : (System.Int32?)reader["IDKlijent"];
			//entity.IDKlijent = (Convert.IsDBNull(reader["IDKlijent"]))?(int)0:(System.Int32?)reader["IDKlijent"];
			entity.IDOrganizacija = (System.Int32)reader["IDOrganizacija"];
			//entity.IDOrganizacija = (Convert.IsDBNull(reader["IDOrganizacija"]))?(int)0:(System.Int32)reader["IDOrganizacija"];
			entity.Mjesto = reader.IsDBNull(reader.GetOrdinal("Mjesto")) ? null : (System.String)reader["Mjesto"];
			//entity.Mjesto = (Convert.IsDBNull(reader["Mjesto"]))?string.Empty:(System.String)reader["Mjesto"];
			entity.OrgSifra = (System.String)reader["OrgSifra"];
			//entity.OrgSifra = (Convert.IsDBNull(reader["OrgSifra"]))?string.Empty:(System.String)reader["OrgSifra"];
			entity.OrgNaziv = (System.String)reader["OrgNaziv"];
			//entity.OrgNaziv = (Convert.IsDBNull(reader["OrgNaziv"]))?string.Empty:(System.String)reader["OrgNaziv"];
			entity.RedniBrojStavke = reader.IsDBNull(reader.GetOrdinal("RedniBrojStavke")) ? null : (System.Int64?)reader["RedniBrojStavke"];
			//entity.RedniBrojStavke = (Convert.IsDBNull(reader["RedniBrojStavke"]))?(long)0:(System.Int64?)reader["RedniBrojStavke"];
			entity.TipStavke = (System.Int32)reader["TipStavke"];
			//entity.TipStavke = (Convert.IsDBNull(reader["TipStavke"]))?(int)0:(System.Int32)reader["TipStavke"];
			entity.NazivTipStavke = (System.String)reader["NazivTipStavke"];
			//entity.NazivTipStavke = (Convert.IsDBNull(reader["NazivTipStavke"]))?string.Empty:(System.String)reader["NazivTipStavke"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwBlagajnaStavka"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwBlagajnaStavka"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwBlagajnaStavka entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
			entity.IDBlagajnaIzvjestaj = (Convert.IsDBNull(dataRow["IDBlagajnaIzvjestaj"]))?(int)0:(System.Int32)dataRow["IDBlagajnaIzvjestaj"];
			entity.DatumDokumenta = (Convert.IsDBNull(dataRow["DatumDokumenta"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumDokumenta"];
			entity.Ulaz = (Convert.IsDBNull(dataRow["Ulaz"]))?0:(System.Decimal)dataRow["Ulaz"];
			entity.Izlaz = (Convert.IsDBNull(dataRow["Izlaz"]))?0:(System.Decimal)dataRow["Izlaz"];
			entity.DateUICreated = (Convert.IsDBNull(dataRow["DateUICreated"]))?DateTime.MinValue:(System.DateTime)dataRow["DateUICreated"];
			entity.Opis = (Convert.IsDBNull(dataRow["Opis"]))?string.Empty:(System.String)dataRow["Opis"];
			entity.IDKonto = (Convert.IsDBNull(dataRow["IDKonto"]))?(int)0:(System.Int32)dataRow["IDKonto"];
			entity.KontoSifra = (Convert.IsDBNull(dataRow["KontoSifra"]))?string.Empty:(System.String)dataRow["KontoSifra"];
			entity.Primatelj = (Convert.IsDBNull(dataRow["Primatelj"]))?string.Empty:(System.String)dataRow["Primatelj"];
			entity.IDKlijent = (Convert.IsDBNull(dataRow["IDKlijent"]))?(int)0:(System.Int32?)dataRow["IDKlijent"];
			entity.IDOrganizacija = (Convert.IsDBNull(dataRow["IDOrganizacija"]))?(int)0:(System.Int32)dataRow["IDOrganizacija"];
			entity.Mjesto = (Convert.IsDBNull(dataRow["Mjesto"]))?string.Empty:(System.String)dataRow["Mjesto"];
			entity.OrgSifra = (Convert.IsDBNull(dataRow["OrgSifra"]))?string.Empty:(System.String)dataRow["OrgSifra"];
			entity.OrgNaziv = (Convert.IsDBNull(dataRow["OrgNaziv"]))?string.Empty:(System.String)dataRow["OrgNaziv"];
			entity.RedniBrojStavke = (Convert.IsDBNull(dataRow["RedniBrojStavke"]))?(long)0:(System.Int64?)dataRow["RedniBrojStavke"];
			entity.TipStavke = (Convert.IsDBNull(dataRow["TipStavke"]))?(int)0:(System.Int32)dataRow["TipStavke"];
			entity.NazivTipStavke = (Convert.IsDBNull(dataRow["NazivTipStavke"]))?string.Empty:(System.String)dataRow["NazivTipStavke"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwBlagajnaStavkaFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwBlagajnaStavka"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwBlagajnaStavkaFilterBuilder : SqlFilterBuilder<VwBlagajnaStavkaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwBlagajnaStavkaFilterBuilder class.
		/// </summary>
		public VwBlagajnaStavkaFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwBlagajnaStavkaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwBlagajnaStavkaFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwBlagajnaStavkaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwBlagajnaStavkaFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwBlagajnaStavkaFilterBuilder

	#region VwBlagajnaStavkaParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwBlagajnaStavka"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwBlagajnaStavkaParameterBuilder : ParameterizedSqlFilterBuilder<VwBlagajnaStavkaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwBlagajnaStavkaParameterBuilder class.
		/// </summary>
		public VwBlagajnaStavkaParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwBlagajnaStavkaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwBlagajnaStavkaParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwBlagajnaStavkaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwBlagajnaStavkaParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwBlagajnaStavkaParameterBuilder
} // end namespace
